package chemxy.oms.pojo.result;

public class Result {
    private Integer code;
    private String message;
    private Object data;

    private static final Integer SUCCESS = 200;
    private static final Integer PARAMS_ERROR = 400;
    private static final Integer UNAUTHORIZED = 401;
    private static final Integer FORBIDDEN = 403;
    private static final Integer NOT_FOUND = 404;
    private static final Integer INTERNAL_ERROR = 500;

    private Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result success() {
        return new Result(SUCCESS, "success", null);
    }

    public static Result success(Object data) {
        return new Result(SUCCESS, "success", data);
    }

    public static Result paramsError() {
        return new Result(PARAMS_ERROR, "params error", null);
    }

    public static Result unauthorized() {
        return new Result(UNAUTHORIZED, "unauthorized", null);
    }

    public static Result forbidden() {
        return new Result(FORBIDDEN, "forbidden", null);
    }

    public static Result notFound() {
        return new Result(NOT_FOUND, "not found", null);
    }

    public static Result internalError() {
        return new Result(INTERNAL_ERROR, "internal error", null);
    }
}
